﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LiteQuery
{
    public partial class ImportGuide : Form
    {
        List<Controls.FileRowPanel> _rows;
        public List<Controls.FileRowPanel> Rows
        {
            get { return _rows; }
        }

        public ImportGuide()
        {
            InitializeComponent();
            _rows = new List<Controls.FileRowPanel>();
        }

        private void btnFile_Click(object sender, EventArgs e)
        {
            var diag = new OpenFileDialog()
            {
                Multiselect = true,
                Title = "选择数据源"
            };
            if (diag.ShowDialog() == DialogResult.OK && diag.FileNames.Length > 0)
            {
                foreach (string item in diag.FileNames)
                {
                    var file = new System.IO.FileInfo(item);
                    this.txtPath.Text = file.DirectoryName;
                    var row = new Controls.FileRowPanel(file);
                    row.OnRemoved += (ss, ee) =>
                    {
                        if(_rows.Contains(row))
                            _rows.Remove(row);
                    };
                    _rows.Add(row);
                    flpFileList.Controls.Add(row);
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnImport_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
    }
}
